@extends('common.admin-master')

@section('html-body')
    <div class="content">

        <div class="header">
            <div class="stats">
                <p class="stat"><a href="{{route('Admin')}}">返回首页</a></p>
            </div>
            <h1 class="page-title">项目管理</h1>
        </div>

        <ul id="myTab" class="nav nav-tabs">
            <li class="active"><a href="#new_creater" data-toggle="tab">编辑项目</a></li>
        </ul>

        <div class="container-fluid">
            <div class="row-fluid">
                <div class="row-fluid">
                    <div id="TabContent" class="tab-content">
                        <div class="tab-pane fade  in active" id="new_creater">
                            <div class="container-fluid">
                                <div class="row-fluid">
                                    <div class="well">
                                        <ul class="nav nav-tabs">
                                            <li class="active"><a href="#detail" data-toggle="tab">项目详情</a></li>
                                            <li><a href="#intro" data-toggle="tab">项目介绍</a></li>
                                            <li><a href="#planbook" data-toggle="tab">商业计划书</a></li>
                                            <li><a href="#team" data-toggle="tab">创始团队</a></li>
                                            <li><a href="#milestone" data-toggle="tab">里程碑</a></li>
                                            <li><a href="#financed" data-toggle="tab">已经融资</a></li>
                                            <li><a href="#need_finance" data-toggle="tab">需求融资</a></li>
                                            <li><a href="#index" data-toggle="tab">项目指数</a></li>
                                        </ul>
                                        <div id="myTabContent" class="tab-content">
                                            <div class="tab-pane active in" id="detail">
                                                <form method="post" id="form_detail" >
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <label>项目logo</label>
                                                    <em class="pro-name"></em><a class="logo" href="javascript:void(0);" id="inputImage">
                                                        <img id="project_logo_url" src="{{route('Api.CreateProjectLogo.Show' ,['id'=>isset($project->id)?$project->id:0])}}" title="点击上传" width="100" height="100" /></a>
                                                    <input type="hidden" id="img_projectlogo_id" name="img_projectlogo_id" value="@if($id =$project->id) {{$id}}@else 0 @endif" /><em
                                                            class="msg"></em>
                                                    <label>项目名称</label>
                                                    <input type="text" name="project_name" class="input-xlarge"
                                                           value="{{$project->project_name}}">
                                                    <label>公司名称</label>
                                                    <input type="text" name="company" class="input-xlarge" value="{{$project->company}}">
                                                    <label>一句话介绍</label>
                                                    <textarea name="project_intro" style="width: 500px;"
                                                              rows="2">{{$project->project_intro}}</textarea>
                                                    <label>项目描述</label>
                                                    <textarea name="project_desc" style="width: 500px;"
                                                              rows="2">{{$project->project_desc}}</textarea>
                                                    <label>所在地</label>
                                                    <select name="province">
                                                        @if(!is_null($project->province))
                                                        <option value="{{$project->province}}">{{$project->province}}</option>
                                                        @endif
                                                        @if($provinces = \App\District::all())
                                                        @foreach($provinces as $province)
                                                                <option value="{{$province->dist_name}}">{{$province->dist_name}}</option>
                                                        @endforeach
                                                        @endif
                                                    </select>
                                                    <input type="text" name="city" placeholder="市区" class="input-xlarge" value="@if($city = $project->city)  {{$project->city}} @endif">

                                                    <label>时间</label>
                                                    <p id="createDate">
                                                        <input type="text" name="create_time"
                                                        @if($project->create_time)
                                                               value="{{date('Y-m-d' , strtotime($project->create_time))}}"
                                                        @else
                                                               placeholder="请选择开始时间"
                                                        @endif
                                                               class="date start" />
                                                    </p>

                                                    <label>行业</label>
                                                    @if($fields = \App\Fields::get())
                                                        @foreach($fields as $key=>$field)
                                                            <input type="checkbox" class="field" name="fields[]"
                                                                   value="{{$field->id}}"
                                                                   @if($fields_ = $project->project_x_fields)
                                                                       @foreach($fields_ as $field_)
                                                                           @if($field->id == $field_->id)
                                                                                 checked="checked"
                                                                           @endif
                                                                       @endforeach
                                                                   @endif>
                                                            {{$field->field}} &nbsp;
                                                            @if($key==10)
                                                                <br>
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                    <br/>
                                                    <br/>
                                                    <label>项目阶段</label>
                                                    @if($phases = \App\Phases::all())
                                                        @foreach($phases  as $key => $phase)
                                                            <input  type="radio" name="phase_id" value="{{$phase->id}}"
                                                            @if($phases_ = $project->toPhase)
                                                                @if($phase->id == $phases_->id)
                                                                    checked="checked"
                                                                        @endif
                                                                    @endif    >{{$phase->phase}} &nbsp;
                                                            @if($key == 10)
                                                                <br/>
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                    <br/>
                                                    <br/>
                                                    <label>项目标签</label>
                                                    <input type="text" class="input-xlarge tags" name="tag" value="@if($tags = $project->getProjectTagsById($project->id)) {{$project->getProjectTagsById($project->id)}} @endif"/>
                                                    <span class="pro_tag"><span style="paddind-left:10px;color:red;">*</span>请用 ',' 分割</span>

                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-primary  save_detail"><i class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                    <input type="hidden" id="project_id" name="project_id" value="{{isset($project->id)?$project->id:0}}">
                                                </form>

                                            </div>
                                            <div class="tab-pane fade" id="intro">
                                                <label>项目总览</label>
                                                <div class="overview">
                                                    @if($images = $project->project_x_overview_img)
                                                    @foreach($images as $image)
                                                    <span class="image">
                                                        <img src="{{route('Api.Project.getProjectOverviewImgByImgId' ,['id'=>$image->id])}}" style="width:100px;height: 100px;"/>
                                                        <span class="del-btn" data="{{$image->id}}" style="position:relative;
                                                        width:100px;height: 20px;">删除</span>
                                                    </span>
                                                    @endforeach
                                                    @endif
                                                </div>
                                                <form method="post" id="form_intro" action="{{route('Api.Project.EditProject')}}" >
                                                <em class="pro-name"></em><a class="logo" href="javascript:void(0);" id="demoImage">
                                                    <img id="demo_logo_url" src="{{route('Api.Photo.Show',['id'=>0])}}" title="点击上传" width="100" height="100" /></a>
                                                <input type="hidden" id="demo_img_id" name="demo_img_id"  value="0"
                                                        /><em class="demo_msg"></em>
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <label>项目描述</label>
                                                    <textarea style="width: 500px;" rows="5"
                                                              name="project_desc">{{$project->project_desc}}</textarea>
                                                    <label>项目亮点</label>
                                                    <textarea style="width: 500px;" rows="5"
                                                              name="project_lightspot">{{$project->project_lightspot}}</textarea>
                                                    <label>项目前景</label>
                                                    <textarea style="width: 500px;" rows="5" name="project_future">{{$project->project_future}}</textarea>
                                                    <label>项目链接</label>
                                                    <label>PC端链接</label>
                                                    <input name="web_url" class="input-xxlarge"
                                                           value="{{$project->getProjectLink($project->id,'web')}}">
                                                    <label>安卓端链接</label>
                                                    <input name="android_url" class="input-xxlarge" value="{{$project->getProjectLink($project->id,'android')}}">
                                                    <label>IOS端链接</label>
                                                    <input name="ios_url" class="input-xxlarge" value="{{$project->getProjectLink($project->id,'ios')}}">

                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-primary save_intro">
                                                                <i class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                            <div class="tab-pane fade " id="planbook">
                                                <div id="show_bp"></div>
                                                <form method="post" action="{{route('Api.Project.EditProject')}}" id="form_planbook">
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <label>商业计划书</label><br/>
                                                    @if($project->project_x_fields)
                                                    @if($bp_id = $project->file_bp_id)
                                                    @else
                                                        <hidden value='{{$bp_id=0}}'/>
                                                    @endif
                                                    @endif
                                                    <a href="{{route("Api.File.DownLoad" , ['id'=>$bp_id])}}" class="show_a_bp">
                                                        @if($project->toBpFile)
                                                        @if($file_name = $project->toBpFile->file_name)
                                                            {{$file_name}}<br/>
                                                        @endif
                                                        @endif
                                                    </a><br/>
                                                    <em class="c-upbtn"><button id="upload_bp">点击上传</button>
                                                        <input type="hidden" id='file_id' name="file_bp_id" value="{{$project->file_bp_id}}">
                                                        <em class="upload_msg" style="display: none;">上传文件...</em></em>
                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button class="btn btn-primary save_planbook"
                                                                    type="button"><i class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                                <div class="tab-pane fade" id="team">
                                                <div class="team_msgs">
                                                    @if($teams = $project->project_x_team)
                                                        @foreach($teams as $team)
                                                            <div class="team_msg">
                                                                <label>{{$team->real_name}}</label>
                                                                <img src="{{route('Api.ProjectTeamLogo.Show',
                                                            ['id'=>$team->photo_id])}}" style="width:100px;height: 100px;">
                                                                <div>
                                                                    <span class="edit_team"
                                                                          data="{{$team->id}}">编辑</span>
                                                                    <span class="del_team"
                                                                          data="{{$team->id}}">删除</span>
                                                                </div>
                                                            </div>
                                                        @endforeach
                                                    @endif
                                                </div>

                                                <div class="team_opt">
                                                    <button type="button" class="add-team">添加成员</button>
                                                </div>
                                                <div class="teams-detail" style="display: none;">
                                                <form method="post" id="form_team" action="{{route('Api.UserInfo.EditUserTeams')}}" >
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <label>团队logo</label><em class="pro-name"></em><a class="logo" href="javascript:void(0);" id="inputImage_team">
                                                        <img id="team_photo_url" src="{{route('Api.ProjectTeamLogo.Show' , ['id'=>0])}}" title="点击上传logo" width="100" height="100" /></a><input
                                                            type="hidden" id="team_photo_id" name="photo_id" value="0"/><em
                                                            class="team_msg"></em>
                                                    <label>姓名</label>
                                                    <input type="text" name="realname" class="input-xlarge">
                                                    <label>职位</label>
                                                    <input type="text" name="position" class="input-xlarge">
                                                    <label>创始人</label>
                                                    <input type="radio" name="is_founder" value="1">创始人
                                                    <input type="radio" name="is_founder" value="0"
                                                           checked="checked">团队成员
                                                    <br/><br/>
                                                    <label>毕业院校</label>
                                                    <input type="text" name="school" class="input-xlarge">
                                                    <label>团队简介</label>
                                                    <textarea style="width: 500px;" rows="5"  name="team_desc"></textarea>

                                                    <label>微博</label>
                                                    <input type="text" name="weibo" class="input-xlarge">
                                                    <label>微信</label>
                                                    <input type="text" name="wechat" class="input-xlarge">
                                                    <label>脉脉</label>
                                                    <input type="text" name="maimai" class="input-xlarge">
                                                    <input type="hidden" name="project_id" value="@if($id = $project->id){$id}}@else 0 @endif"/>
                                                    <input type="hidden" id="teamId" value="0"/>
                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button class="btn btn-primary save_team" type="button"><i
                                                                        class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                                </div>
                                            </div>
                                            <div class="tab-pane fade" id="milestone">
                                                <div class="milestone">
                                                    @if($milestones = $project->projectMilestone)
                                                        @foreach($milestones as $milestone)
                                                            <span>
                                                            <label>{{date('Y-m-d',strtotime($milestone->mil_time))}}</label>
                                                            <input type="text" class="input-xlarge"
                                                                   value="{{$milestone->mil_desc}}">
                                                            <button type="button" data="{{$milestone->id}}" class="btn del_mil">删除</button>
                                                            <button type="button" data="{{$milestone->id}}" class="btn update_mil">编辑</button>
                                                            </span>
                                                        @endforeach
                                                    @endif
                                                </div>
                                                <form method="post" id="form_mil" action="{{route('Api.Project.EditProjectMilestone')}}" >
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <input type="hidden" name="project_id" value="{{$project->id}}"/>
                                                    <input type="hidden" name="mil_id" value="0"/>
                                                    <label>时间</label>
                                                    <p id="dateOnlyExample">
                                                        <input type="text" name="mil_time" placeholder="请选择开始时间" class="date" />
                                                    </p>
                                                    <label>里程碑事件</label>
                                                    <input type="text" name="mil_desc" class="input-xlarge">
                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-primary save_mil"><i
                                                                        class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                            <div class="tab-pane fade" id="financed">
                                                <ul>
                                                    <label>已经融资列表</label>
                                                    <table class="invest-log" style=" width:70% ; text-align: center;">
                                                        <tr class="th">
                                                            <th>编号</th>
                                                            <th>融资金额</th>
                                                            <th>融资时间</th>
                                                            <th>投资机构</th>
                                                            <th>投资人</th>
                                                            <th>操作</th>
                                                        </tr>

                                                    @if($investLogs = $project->getInvestLogById($project->id))
                                                        @foreach($investLogs as $key=>$investLog)
                                                       <tr>
                                                           <td>{{$key+1}}</td>
                                                           <td class="account">{{$investLog->invest_account}}</td>
                                                           <td class="time">@if($investLog->invest_time!=null)
                                                                   {{date('Y-m-d' ,strtotime($investLog->invest_time))}}
                                                               @else
                                                                    暂无数据
                                                               @endif
                                                           </td>
                                                           <td>@if($org=$investLog->toInvestOrg) {{$org->invest_name}}  @else 暂无数据 @endif</td>
                                                           <td>@if($investor=$investLog->toUser) {{$investor->realname}} @else 暂无数据 @endif</td>
                                                           <td>
                                                               <a class="edit-log" href="javascript:;"  data="{{$investLog->id}}">编辑</a>
                                                               <a class="del-log"  href="javascript:;"  data="{{$investLog->id}}">删除</a>
                                                           </td>
                                                       </tr>
                                                        @endforeach
                                                    @endif
                                                    </table>
                                                </ul>
                                                <form method="get" id="form_log" >
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <input type="hidden" name="project_id" value="{{isset($project->id)?$project->id:0}}"/>
                                                    <input type="hidden" name="log_id" value="0"/>
                                                    <label>融资金额</label>
                                                    <input type="text" name="invest_account" class="input-xlarge">
                                                    <label>融资时间</label>
                                                    <p id="logDate">
                                                        <input type="text" name="invest_time"  class="date" value="{{date('Y-m-d' , time())}}" />
                                                    </p>

                                                    <label>投资机构</label>
                                                    <select name="org_id">
                                                        <option value="0">选择投资机构</option>
                                                    @if($orgs = \App\InvestOrg::all())
                                                            @foreach($orgs as $org)
                                                                <option value="{{$org->id}}">{{$org->invest_name}}</option>
                                                            @endforeach
                                                        @endif
                                                    </select>
                                                    <label>投资人</label>
                                                    <select name="user_id">
                                                        <option value="0">选择投资人</option>
                                                    @if($investors = \App\User::whereRole(1)->get())
                                                            @foreach($investors as $investor)
                                                                @if($investor->userInfo)
                                                                    <option value="{{$investor->userInfo->id}}">{{$investor->userInfo->realname}}</option>
                                                                @endif
                                                            @endforeach
                                                        @endif
                                                    </select>
                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button class="btn btn-primary save_log" type="button"><i
                                                                        class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                            <div class="tab-pane fade" id="need_finance">
                                                <form method="post" id="form_need" action="{{route('Api.Project.EditProject')}}" >
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <input type="hidden" name="project_id" value="@if($id = $project->id)
                                                    {{$id}}@else 0 @endif"/>
                                                    <label>融资阶段</label>
                                                    @if($phases = \App\Phases::all())
                                                        @foreach($phases  as $key => $phase)
                                                            <input  type="radio" name="invet_phase_id" value="{{$phase->id}}"
                                                            @if($phases_ = $project->toInvetPhase)
                                                                @if($phase->id == $phases_->id)
                                                                    checked="checked"
                                                                        @endif
                                                                    @endif    >{{$phase->phase}} &nbsp;
                                                            @if($key == 10)
                                                                <br/>
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                    <label>融资金额</label>
                                                    <input type="text" name="invet" class="input-xlarge" value="{{$project->invet}}">
                                                    <label>出让股权</label>
                                                    <input type="text" name="sell_stock" class="input-xlarge"
                                                           value="{{$project->sell_stock}}">
                                                    <label>最低限额</label>
                                                    <input type="text" name="min_money" class="input-xlarge" value="{{$project->min_money}}">
                                                    <label>投资数量</label>
                                                    <input type="text" name="invest_num" class="input-xlarge"
                                                           value="{{$project->invest_num}}">
                                                    <label>其他要求</label>
                                                    <textarea name="other_desc" >{{$project->other_desc}}</textarea>
                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button class="btn btn-primary save_need" type="button"><i
                                                                        class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                            <div class="tab-pane fade" id="index">
                                                <form method="post" id="form_index" action="{{route('Api.Project.EditProject')}}" >
                                                    <input type="hidden" name="is_admin" value="0"/>
                                                    <input type="hidden" name="project_id" value="@if($id = $project->id)
                                                    {{$id}}@else 0 @endif"/>
                                                    <label>项目属性</label>
                                                    <input type="radio" name="is_finance" value="2" @if($project->is_finance==2) checked="checked" @endif>快速融资&nbsp;
                                                    <input type="radio" name="is_finance" value="1" @if($project->is_finance==1) checked="checked" @endif>正在融资&nbsp;
                                                    <input type="radio" name="is_finance" value="3" @if($project->is_finance==3) checked="checked" @endif>完成融资&nbsp;<br/>
                                                    <br/>

                                                    <label>预估回报率</label>
                                                    <input type="text" name="repay_rate" class="input-xlarge"
                                                           value="{{$project->repay_rate}}">
                                                    <label>靠谱指数</label>
                                                    <input type="text" name="star_layer" class="input-xlarge"
                                                           value="{{$project->star_layer}}">
                                                    <div class="btn-toolbar">
                                                        <div class="btn-group">
                                                            <button class="btn btn-primary save_index" type="button"><i
                                                                        class="icon-save"></i> Save</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>

                                    </div>

                                    <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                            <h3 id="myModalLabel">Delete Confirmation</h3>
                                        </div>
                                        <div class="modal-body">

                                            <p class="error-text"><i class="icon-warning-sign
                                            modal-icon"></i>您确定要放弃本次操作吗?</p>
                                        </div>
                                        <div class="modal-footer">
                                            <button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
                                            <button class="btn btn-danger yes" data-dismiss="modal">Yes</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script>
        var EditProject             =   "{{route('Api.Project.EditProject',['id'=>0])}}";
        var EditUserTeams           =   "{{route('Api.UserInfo.EditUserTeams' , ['id'=>0])}}";
        var EditProjectMilestone    =   "{{route('Api.Project.EditProjectMilestone' ,['id'=>0])}}";
        var EditInvestLog           =   "{{route('Api.InvestLog.EditInvestLog' ,['id'=>0])}}";
        var delMilestone            =   "{{route('Api.Admin.DeleteMilestone')}}";
        var delProjectField         =   "{{route('Api.Admin.delProjectField')}}";
        var delOverviewImage        =   "{{route('Api.Admin.delOverviewImage')}}";
        var delTeamByProIdAndTeamId =   "{{route('Api.Admin.delTeamByProIdAndTeamId')}}";
        var getTeamByTeamId         =   "{{route('Api.Admin.getTeamByTeamId')}}";
        var getTeamByProId          =   "{{route('Api.Admin.getTeamByProId')}}";
        var getMilestoneByProId     =   "{{route('Api.Admin.getMilestoneByProId')}}";
        var getInvestLogByProjectId =   "{{route('Api.InvestLog.getInvestLogByProjectId')}}";
        var delInvestLogById        =   "{{route('Api.InvestLog.delInvestLogById')}}";
    </script>

    <script src="{{url('/js/admin/project.js')}}"></script>
    <script src="{{url('/js/admin/teams.js')}}"></script>
    <script src="{{url('/js/admin/tags.js')}}"></script>
    <script src="{{url('/js/admin/milestone.js')}}"></script>
    <link  href="{{url('js/lib/time/bootstrap-datepicker.css')}}" type="text/css" rel="stylesheet"/>
    <script src="{{url('js/lib/time/bootstrap-datepicker.js')}}"></script>
    <script src="{{url('/js/admin/investLog.js')}}"></script>
    <script>
        $('#dateOnlyExample .date').datepicker({
            'format': 'yyyy-m-d',
            'autoclose': true
        });

        $('#createDate .date').datepicker({
            'format':'yyyy-m-d',
            'autoclose':true
        });

        $('#logDate .date').datepicker({
            'format' : 'yyyy-m-d',
            'autoclose' : true
        });
    </script>
    <script type="text/javascript">
        $("[rel=tooltip]").tooltip();
        $(function() {
            $('.demo-cancel-click').click(function(){return false;});
        });

        $('#nav_tab a').click(function (e) {
            e.preventDefault();
            $(this).tab('show');
        })

        var tmp = 0 ;       //用来判断图片是否上传
        function  loadImg(button , photo_id , photo_url , msg){
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: button ,
                url: '{{ url('api/upload/image') }}',

                filters: {
                    max_file_size: '50mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {
                    _token: '{{ csrf_token() }}'
                },

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {
                        $('#'+msg).html('上传中...');
                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            callback: {
                                afterClose: function () {
                                    $('#'+button).show();
                                    $('#inputImageProgress').hide();
                                }
                            }
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        var $inputImage = $('.msg');
                        $inputImage.html('上传成功！');
                        $inputImage.show();

                        var imageUrl = '', imageId = 0;
                        if (responseObj && responseObj.data) {
                            var d = new Date();
                            imageUrl = "{{route('Api.Images.Show')}}?"+d.getTime();
                            imageId = responseObj.data.id;
                        }
                        $('#'+photo_url).attr('src', imageUrl);
                        if(imageId !== null){
                            $('#'+photo_id).val(imageId);
                        }else{
                            $('#'+photo_id).val('0');
                        }
                        uploadAfter() ;
                    }
                }
            });
            uploader.init();
        }
        /** 上传项目logo图片 **/
        loadImg('inputImage' , 'img_projectlogo_id' , 'project_logo_url' , 'msg');

        /** 上传团队照片 */
        loadImg('inputImage_team' , 'team_photo_id' , 'team_photo_url' , 'team_msg');

        /** 图片修改完上传 */
        function uploadAfter(){
            var proId   = $('#project_id').val();
            var url     = EditProject + proId ;
            var logoId  = $('#img_projectlogo_id').val();
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: {
                    'img_projectlogo_id' : logoId
                },
                success: function (obj) {
                    if (obj.level === "success") {
                        $('#project_id').val(obj.data.id);
                    }
                }
            });
        }

        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'upload_bp',
            url: '{{ url('api/upload/file')  }}',

            filters: {
                max_file_size: '50mb',
                mime_types: [
                ],
                prevent_duplicates: false
            },
            multi_selection: true,
            unique_names: true,

            flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
            silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

            file_data_name: 'file',
            headers: {
                Accept: 'application/json'
            },

            multipart_params: {
                _token: '{{ csrf_token() }}'
            },

            init: {
                PostInit: function () {
                },

                FilesAdded: function (up, files) {
                    up.start();
                },

                BeforeUpload: function (up, file) {
                    up.settings.multipart_params.file_name = file.name;
                    $('.upload_msg').show();
                },

                UploadProgress: function (up, file) {
                    $('.upload_msg').html('上传中...('+ file.percent + "%)");
                },

                Error: function (up, err) {
                    var responseObj = '', responseMessage = '';
                    try {
                        responseObj = $.parseJSON(err.response);
                        responseMessage = responseObj.message;
                    } catch ($e) {

                    }

                    noty({
                        type: 'error',
                        text: err.message + ' ' + responseMessage,
                        callback: {
                            afterClose: function () {
                                $('#inputImage').show();
                                $('#inputImageProgress').hide();
                            }
                        }
                    });
                },

                FileUploaded: function (up, file, info) {
                    var responseObj = '', responseMessage = '';
                    try {
                        responseObj = $.parseJSON(info.response);
                    } catch ($e) {

                    }
                    if (responseObj && responseObj.data) {
                        var $inputImage = $('.upload_msg');
                        var id = responseObj.data.id;
                        $('#file_id').val(id);
                        $('#show_bp').html("<a href='/api/file/download/"+id+"'>【"+ responseObj.data.file_name+"】");
                        $('.show_a_bp').hide();
                        $inputImage.show();
                    }
                }
            }
        });
        uploader.init();
    </script>

    <script>
    /**  项目总览图片上传 */
    var ids = '';
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'demoImage' ,
        url: '{{ url('api/upload/image') }}',

        chunk_size: '2mb',
        filters: {
            max_file_size: '10mb',
            mime_types: [
                {title: "Image files", extensions: "jpg,gif,png"}
            ],
            prevent_duplicates: false
        },
        multi_selection: true,
        unique_names: true,

        flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
        silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

        file_data_name: 'photo',
        headers: {
            Accept: 'application/json'
        },

        multipart_params: {
            _token: '{{ csrf_token() }}'
        },

        init: {
            PostInit: function () {
            },

            FilesAdded: function (up, files) {
                up.start();
            },

            BeforeUpload: function (up, file) {
                up.settings.multipart_params.file_name = file.name;
            },

            UploadProgress: function (up, file) {
                $('#msg_demo').html('上传中...');
            },

            Error: function (up, err) {
                var responseObj = '', responseMessage = '';
                try {
                    responseObj = $.parseJSON(err.response);
                    responseMessage = responseObj.message;
                } catch ($e) {

                }

                noty({
                    type: 'error',
                    text: err.message + ' ' + responseMessage,
                    callback: {
                        afterClose: function () {
                            $('#demoImage').show();
                            $('#inputImageProgress').hide();
                        }
                    }
                });
            },

            FileUploaded: function (up, file, info) {
                var responseObj = '', responseMessage = '';
                try {
                    responseObj = $.parseJSON(info.response);
                    responseMessage = responseObj.message;
                } catch ($e) {

                }

                var $inputImage = $('.msg_demo');
                $inputImage.html('上传成功！');
                $inputImage.show();

                var imageUrl = '', imageId = 0;
                if (responseObj && responseObj.data) {
                    var d = new Date();
                    imageUrl = "{{route('Api.Images.Show')}}?"+d.getTime();
                    imageId  = responseObj.data.id;
                }
                ids  += imageId + ',';

                var Str = ' <span class="image"><img src="'+imageUrl+'" style="width:100px;height:' +
                        ' 100px;' +'"/><span class="del-btn" data="'+imageId+'" ' +
                        'style="position:relative; width:100px;height: 20px;'
                        +'">删除</span></span>';

                var once = $('.overview').html();

                if(!once){
                    once = '';
                }
                $('.overview').html(once + Str);

                if(imageId !== null){
                    $('#demo_img_id').val(ids);
                }else{
                    $('#demo_img_id').val('0');
                }
            }
        }
    });
    uploader.init();

    </script>


@endsection


